export default {
	data() {
		return {
			latitude: 0,
			longitude: 0,
		}
	},
	methods: {
		getLocation(callback) {
			// #ifdef MP
			uni.getLocation({
				type: 'wgs84',
				success: (res) => {
					const {
						latitude,
						longitude
					} = res;
					this.latitude = latitude;
					this.longitude = longitude;
					callback && callback();
				},
				fail: (res) => {
					console.log(res);
					if (res.errMsg == 'getLocation:fail auth deny') {
						uni.showModal({
							title: '获取定位失败',
							content: "需要获取您的位置信息",
							confirmText: '去设置',
							success: (res) => {
								if (res.confirm) {
									this.openSetting(callback);
								}
							}
						})
					} else {
						callback && callback();
					}
				}
			})
			// #endif
			// #ifndef MP
			callback && callback();
			// #endif
		},
		openSetting(callback) {
			uni.openSetting({
				success: (res) => {
					console.log(res);
					if (res.authSetting["scope.userLocation"]) {
						this.getLocation(callback);
					} else {
						callback && callback();
					}
				}
			});
		}
	}
}